<template>
  <transition name="el-zoom-in-center">
    <div class="JADP-preview-main">
      <div class="JADP-common-page-header">
        <el-page-header
          @back="goBack"
          :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"
        />
        <div class="options">
          <el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail"
            >确 定</el-button
          >
          <el-button @click="goBack">取 消</el-button>
        </div>
      </div>
      <el-row
        :gutter="15"
        class="main"
        :style="{ margin: '0 auto', width: '100%' }"
      >
        <el-form
          ref="elForm"
          :model="dataForm"
          :rules="rules"
          size="small"
          label-width="100px"
          label-position="right"
          :disabled="!!isDetail"
        >
          <el-col :span="12">
            <el-form-item label="姓名" prop="papersname">
              <user-select
                v-model="dataForm.papersname"
                placeholder="请选择"
                :multiple="false"
              >
              </user-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="公司" prop="paperscompany">
              <el-input
                v-model="dataForm.paperscompany"
                placeholder="系统自动生成"
                readonly
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="部门" prop="createdept">
              <el-input
                v-model="dataForm.createdept"
                placeholder="系统自动生成"
                readonly
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="证件类型" prop="paperstype">
              <el-select
                v-model="dataForm.paperstype"
                placeholder="请选择"
                clearable
                :style="{ width: '100%' }"
                :multiple="false"
              >
                <el-option
                  v-for="(item, index) in paperstypeOptions"
                  :key="index"
                  :label="item.fullName"
                  :value="item.id"
                  :disabled="item.disabled"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="证照号码" prop="papersNum">
              <el-input
                v-model="dataForm.papersNum"
                placeholder="请输入"
                clearable
                :style="{ width: '100%' }"
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="证照颁发机构" prop="papersdept">
              <el-input
                v-model="dataForm.papersdept"
                placeholder="请输入"
                clearable
                :style="{ width: '100%' }"
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="生效日期" prop="starttime">
              <el-date-picker
                v-model="dataForm.starttime"
                placeholder="请选择"
                clearable
                :style="{ width: '100%' }"
                type="date"
                format="yyyy-MM-dd"
                value-format="timestamp"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="失效日期" prop="endtime">
              <el-date-picker
                v-model="dataForm.endtime"
                placeholder="请选择"
                clearable
                :style="{ width: '100%' }"
                type="date"
                format="yyyy-MM-dd"
                value-format="timestamp"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="是否年审" prop="nianshen">
              <el-radio-group v-model="dataForm.nianshen" size="small">
                <el-radio
                  v-for="(item, index) in nianshenOptions"
                  :key="index"
                  :label="item.id"
                  :disabled="item.disabled"
                >
                  {{ item.fullName }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="下次年审日期" prop="nextnianshen">
              <el-date-picker
                v-model="dataForm.nextnianshen"
                placeholder="请选择"
                clearable
                :style="{ width: '100%' }"
                type="date"
                format="yyyy-MM-dd"
                value-format="timestamp"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="培训开始日期" prop="trainstarttime">
              <el-date-picker
                v-model="dataForm.trainstarttime"
                placeholder="请选择"
                clearable
                :style="{ width: '100%' }"
                type="date"
                format="yyyy-MM-dd"
                value-format="timestamp"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="培训结束日期" prop="trainendtime">
              <el-date-picker
                v-model="dataForm.trainendtime"
                placeholder="请选择"
                clearable
                :style="{ width: '100%' }"
                type="date"
                format="yyyy-MM-dd"
                value-format="timestamp"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="培训机构" prop="traindept">
              <el-input
                v-model="dataForm.traindept"
                placeholder="请输入"
                clearable
                :style="{ width: '100%' }"
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="状态" prop="status">
              <el-radio-group v-model="dataForm.status" size="small">
                <el-radio
                  v-for="(item, index) in statusOptions"
                  :key="index"
                  :label="item.id"
                  :disabled="item.disabled"
                >
                  {{ item.fullName }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="备注" prop="remarks">
              <el-input
                v-model="dataForm.remarks"
                placeholder="请输入"
                :style="{ width: '100%' }"
                true
                type="textarea"
                :autosize="{ minRows: 4, maxRows: 4 }"
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="创建用户" prop="creatoruserid">
              <el-input
                v-model="dataForm.creatoruserid"
                placeholder="系统自动生成"
                readonly
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="修改时间" prop="lastmodifytime">
              <el-input
                v-model="dataForm.lastmodifytime"
                placeholder="系统自动生成"
                readonly
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="修改用户" prop="lastmodifyuserid">
              <el-input
                v-model="dataForm.lastmodifyuserid"
                placeholder="系统自动生成"
                readonly
              >
              </el-input>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label-width="0">
              <div class="JADP-common-title">
                <h2>证照年审记录明细</h2>
              </div>
              <el-table :data="dataForm.papers_nianshenEntityList" size="mini">
                <el-table-column
                  type="index"
                  width="50"
                  label="序号"
                  align="center"
                />
                <el-table-column prop="nianshendaate" label="年审日期">
                  <template slot-scope="scope">
                    <el-date-picker
                      v-model="scope.row.nianshendaate"
                      placeholder="请选择"
                      clearable
                      :style="{ width: '100%' }"
                      type="date"
                      format="yyyy-MM-dd"
                      value-format="timestamp"
                    >
                    </el-date-picker>
                  </template>
                </el-table-column>
                <el-table-column prop="nianshenresult" label="年审结果">
                  <template slot-scope="scope">
                    <el-select
                      v-model="scope.row.nianshenresult"
                      placeholder="请选择"
                      clearable
                      :style="{ width: '100%' }"
                      :multiple="false"
                    >
                      <el-option
                        v-for="(item, index) in nianshenresultOptions"
                        :key="index"
                        :label="item.fullName"
                        :value="item.id"
                        :disabled="item.disabled"
                      ></el-option>
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column prop="remarks" label="备注">
                  <template slot-scope="scope">
                    <el-input
                      v-model="scope.row.remarks"
                      placeholder="请输入"
                      clearable
                      :style="{ width: '100%' }"
                    >
                    </el-input>
                  </template>
                </el-table-column>
                <el-table-column label="操作" width="50">
                  <template slot-scope="scope">
                    <el-button
                      size="mini"
                      type="text"
                      class="JADP-table-delBtn"
                      @click="handleDelpapers_nianshenEntityList(scope.$index)"
                      >删除
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
              <div
                class="table-actions"
                @click="addHandlepapers_nianshenEntityList()"
              >
                <el-button type="text" icon="el-icon-plus">新增</el-button>
              </div>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
    </div>
  </transition>
</template>
<script>
import request from "@/utils/request";
import { getDictionaryDataSelector } from "@/api/systemData/dictionary";
import { previewDataInterface } from "@/api/systemData/dataInterface";

export default {
  components: {},
  props: [],
  data() {
    return {
      loading: false,
      visible: false,
      isDetail: false,
      dataForm: {
        papersname: undefined,
        paperscompany: "",
        createdept: "",
        paperstype: "",
        papersNum: undefined,
        papersdept: undefined,
        starttime: undefined,
        endtime: undefined,
        nianshen: "",
        nextnianshen: undefined,
        trainstarttime: undefined,
        trainendtime: undefined,
        traindept: undefined,
        status: "",
        remarks: undefined,
        creatoruserid: "",
        creatortime: "",
        lastmodifytime: "",
        lastmodifyuserid: "",
        papers_nianshenEntityList: [],
        organizeId:""
      },
      rules: {},
      paperstypeOptions: [],
      nianshenOptions: [],
      statusOptions: [],
      nianshenresultOptions: [],
    };
  },
  computed: {},
  watch: {},
  created() {
    this.getpaperstypeOptions();
    this.getnianshenOptions();
    this.getstatusOptions();
    this.getnianshenresultOptions();
  },
  mounted() {},
  methods: {
    getpaperstypeOptions() {
      getDictionaryDataSelector("fdaf414ad8e0478c9f8fa6dbf15cfa3c").then(
        (res) => {
          this.paperstypeOptions = res.data.list;
        }
      );
    },
    getnianshenOptions() {
      getDictionaryDataSelector("37b6c2c29a7843aa91838601f4ffd1f2").then(
        (res) => {
          this.nianshenOptions = res.data.list;
        }
      );
    },
    getstatusOptions() {
      getDictionaryDataSelector("37b6c2c29a7843aa91838601f4ffd1f2").then(
        (res) => {
          this.statusOptions = res.data.list;
        }
      );
    },
    getnianshenresultOptions() {
      getDictionaryDataSelector("037ba904515348eaad1c4bd462fc80a6").then(
        (res) => {
          this.nianshenresultOptions = res.data.list;
        }
      );
    },
    goBack() {
      this.$emit("refresh");
    },
    init(id, isDetail) {
      this.dataForm.papers_nianshenEntityList = [];
      this.dataForm.id = id || 0;
      this.visible = true;
      this.isDetail = isDetail || false;
      this.$nextTick(() => {
        this.$refs["elForm"].resetFields();
        if (this.dataForm.id) {
          this.loading = true;
          request({
            url: "/api/hse.pagers/Papers/" + this.dataForm.id+"?organizeId="+this.$store.getters.organizeId,
            method: "get",
          }).then((res) => {
            this.dataForm = res.data;
            this.dataForm.papers_nianshenEntityList = this.dataForm
              .papers_nianshenEntityList
              ? this.dataForm.papers_nianshenEntityList
              : [];
            this.loading = false;
          });
        }
      });
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs["elForm"].validate((valid) => {
        this.dataForm.organizeId = this.$store.getters.organizeId;
        if (valid) {
          if (!this.dataForm.id) {
            request({
              url: `/api/hse.pagers/Papers`,
              method: "post",
              data: this.dataForm,
            }).then((res) => {
              this.$message({
                message: res.msg,
                type: "success",
                duration: 1000,
                onClose: () => {
                  (this.visible = false), this.$emit("refresh", true);
                },
              });
            });
          } else {
            request({
              url: "/api/hse.pagers/Papers/" + this.dataForm.id,
              method: "PUT",
              data: this.dataForm,
            }).then((res) => {
              this.$message({
                message: res.msg,
                type: "success",
                duration: 1000,
                onClose: () => {
                  this.visible = false;
                  this.$emit("refresh", true);
                },
              });
            });
          }
        }
      });
    },
    addHandlepapers_nianshenEntityList() {
      let item = {
        nianshendaate: undefined,

        nianshenresult: undefined,

        remarks: undefined,
      };
      this.dataForm.papers_nianshenEntityList.push(item);
    },
    handleDelpapers_nianshenEntityList(index) {
      this.dataForm.papers_nianshenEntityList.splice(index, 1);
    },
  },
};
</script>




